<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_smbf_t {
        background-color: #254060;
        height: 300px;
        color: white;
        overflow: auto;
    }

    .pa_smbf_but {
        height: 58px;
        line-height: 58px;
        float: right;
        width: 120px;
        font-size: 25px;
        color: white;
        margin-right: 20px;
        text-align: center;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }

    .pa_work_order {
        background-color: #254060;
        height: 80px;
        color: white;
    }

    .line_class {
        background-color: #254060;
        height: 70px;
        color: white;
    }

    .startBut {
        height: 50px;
        line-height: 50px;
        margin-top: 30px;
        margin-left: 12px;
        float: left;
        width: 150px;
        font-size: 18px;
        color: white;
        text-align: center;

    }

    .pa_scbg_ng {
        margin-top: 15px;
        height: 30px;
        line-height: 30px;
        width: 70%;
        margin-left: 2%;
        text-align: center;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟久泰</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:20%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:25%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:15%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 15px;">
            <div class="aui-flex-item-12">
                <p>缺陷原因</p>
            </div>
        </div>

    </div>

    <div class="aui-flex-col aui-flex-center" style="margin-top: 1%;">
        <div class="aui-flex-item-12">
            <div class="aui-flex-col pa_work_order">

                <div class="aui-flex-item-5">
                    <div class="startBut" style="background-color: #528302;" onclick="chooseReturn()">选择带回</div>
                    <div class="startBut" style="background-color: #528302;" onclick="doSearch()">查询</div>

                </div>
            </div>

            <div class="aui-flex-col pa_work_order">
                <div class="aui-flex-item-6">
                    <div class="aui-flex-col pa_scbg_ng">
                        <div class="aui-list-item-inner" style="border: 0;">
                            <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                项目编码：</div>
                            <div class="aui-list-item-input"
                                style="background-color: white;float: left;width: 140px; height: 40px;">
                                <input type="text" id="flawCode" class="aui-input" onclick="getIdSelector();" />
                            </div>
                        </div>
                    </div>

                </div>
                <div class="aui-flex-item-6">
                    <div class="aui-flex-col pa_scbg_ng">
                        <div class="aui-list-item-inner" style="border: 0;">
                            <div class="aui-list-item-label" style="font-size: 20px;float: left;">
                                项目名称：</div>
                            <div class="aui-list-item-input"
                                style="background-color: white;float: left;width: 140px; height: 40px;">
                                <input type="text" id="flawName" class="aui-input" onclick="getIdSelector();" />
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

    </div>
    <div class="aui-flex-item-12">
        <div class="aui-flex-col pa_smbf_t">
            <div class="aui-flex-item-12">
                <div style="height: 100%;width: 100%;">
                    <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                        <thead>
                            <tr style="text-align: center;color: white;font-size: 20px;">
                                <td algin='center' style="width:5%;"></td>
                                <td algin='center' style="width:5%">序号</td>
                                <td algin='center' style="width:25%">项目编码</td>
                                <td algin='center' style="width:25%">项目名称</td>
                            </tr>
                        </thead>
                        <tbody id="scrapDataHtml">
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";
    //光标所在id
    var idSelector = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);
        doSearch()
    }

    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        idSelector = el.id;
        $("#" + el.id).select();
    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //查询缺陷原因
    function doSearch() {
        var flawCode = $("#flawCode").val();
        var flawName = $("#flawName").val();

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getXMPLProject";
        var data = {
            values: {
                flawCode: flawCode,
                flawName: flawName,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    var list = eval(myobj.list);
                    var html = "";
                    var causeOfDeficiency = ""
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        causeOfDeficiency = "causeOfDeficiency_" + i
                        html += "<tr style='text-align: center;color: white;font-size: 14px;height:50px;'>";
                        html += "<td><input name='sub' type='checkbox' /></td>"
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='flawCode'>" + list[i].code + "</td>";
                        html += "<td name='flawName'>" + list[i].name + "</td>";
                        html += "</tr>";
                    }

                    $api.html($api.byId("scrapDataHtml"), html);
                } else {
                    $api.html($api.byId("scrapDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }
    //刷新按钮
    function refresh() {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //查询表格数据
        doSearch();
    }

    $("#containerTm").on('keypress', function (e) { //#keyword为input文本框
        var keycode = e.keyCode;
        var tm = $(this).val();
        if (keycode == '13') {
            if (tm != null && tm != "" && tm != undefined) {
                $("#containerTm").blur();
            }
        }
    });

    //选择带回
    function chooseReturn() {
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        var flawCode = "";
        var flawName = "";
        var flawGid = "";
        var chkItemTypeId = ""
        check.each(function () { //遍历
            var row = $(this).parent("td").parent("tr");
            flawCode = row.find("[name='flawCode']").html();
            flawName = row.find("[name='flawName']").html();
            count++;
        });
        if (count != 1) {
            api.toast({
                msg: '请选择一条表格数据！',
                duration: 3000
            });
            return;
        }

        var pageParam = api.pageParam;
        pageParam.flawCode = flawCode;
        pageParam.flawName = flawName;
        api.closeWin({});
        api.execScript({
            name: api.pageParam.name,
            script: 'setProjectContent(' + JSON.stringify(flawCode) +','+JSON.stringify(flawName) +')'
        });
    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>